<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let b1 = {
            b2: [1, 'abc', console.log],
            b3: function () {
                console.log('b3');
                return function () {
                    return "huidiao";
                }
            }
        };
        console.log(b1.b2[2] instanceof Function);
        b1.b2[2]("hahaha");
        console.log(b1.b3()());

        /* 变量为引用类型时，值会随之变化（保存的为地址）；
            变量为普通类型时，值不会变 
            当引用被覆盖时，两个引用则指向不同的对象，对象的值将不再互相影响    */

        let a = { name: '111' };
        let b = a;
        a.name = '222';
        b.age = 2
        console.log("b = " + a.age);

        let c = '111';
        let d = c;
        c = '222';
        console.log("d = " + d);

        /*         let a = 1;
                function fn(a) {
                    a = 77;
                }
                fn(a);
                console.log(a); */

        let obj1 = { name: 'x' };
        function fn(obj) {
            obj.name = 'y';
        }
        fn(obj1);
        console.log(obj1.name);

        let obj2 = {name: '111'};
        let obj3 = obj2;
        obj2 = {name: '222'};
        console.log(obj3.name);

        function fn2(obj) {
            obj = {name: '333'};    // 创建新对象，成为局部变量
            // obj.name = 333;      // 修改当前对象变量值
        }
        fn2(obj2);
        console.log(obj2.name);

        let hh = 3;
        function fn3(hh) {
            hh = hh + 1;
            // return hh;
        }
        // hh = fn3(hh);    此时hh改值为4
        fn3(hh);
        console.log(hh);
        function fn4(obj) {
            // console.log(obj.name);
            obj.name = 'tt';
        }
        // let objtt = {name: 'tt'};
        let objtt = {};
        fn4(objtt);
        console.log(objtt.name); 

        var aa = 5;
        (function(){
            var aa = 3;
            console.log(aa);
        })();
        console.log(aa);

        (function(){
            var a = 1;
            function test(){
                console.log("a = " + ++a);
            }
            window.$ = function(){
                return {
                    test: test
                }
            }

        })();
        $().test(); 

        function Person(color){
            console.log(this);
            this.color = color;
            this.getColor = function(){
                console.log(this);
                return this.color;
            };
            this.setColor = function(color) {
                console.log(this);
                this.color = color;
            };
        };

        Person("red"); //this-window
        var p = new Person("yellow");
        p.getColor; //this-p
        var objp = {};
        p.setColor.call(objp, "black"); //this-objp
/*         console.log(p);
        console.log(objp); */
        var testp = p.setColor;
        testp(); //this-window

        function fun1() {
            function fun2() {
                console.log(this);
            }
            fun2(); //this-window
        }
        fun1(); //this-window



    </script>
</body>

</html>